package com.yusp75.myexam.com.yusp75.myexam.di

import android.content.Context
import androidx.core.content.edit
import com.yusp75.myexam.com.yusp75.myexam.data.QuestionFilter

class PrefManager(private val context: Context) {
    private val prefs by lazy {
        context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE)
    }

    // 做题顺序
    var exerciseOrder: Int
        get() = prefs.getInt("exercise_order", 0)
        set(value) = prefs.edit() { putInt("exercise_order", value) }

    var exerciseScope: Int
        get() = prefs.getInt("exercise_scope", 0)
        set(value) = prefs.edit() { putInt("exercise_scope", value) }

    var questionType: Int
        get() = prefs.getInt("questionType", 0)
        set(value) = prefs.edit() { putInt("questionType", value) }

    var questionCurrentIdx: Int
        get() = prefs.getInt("questionCurrentIdx", 1)
        set(value) = prefs.edit() { putInt("questionCurrentIdx", value) }

    var choiceCurrentIdx: Int
        get() = prefs.getInt("choiceCurrentIdx", 1)
        set(value) = prefs.edit() { putInt("choiceCurrentIdx", value) }

    var judgeCurrentIdx: Int
        get() = prefs.getInt("judgeCurrentIdx", 1)
        set(value) = prefs.edit() { putInt("judgeCurrentIdx", value) }

    var currentBookId: Int
        get() = prefs.getInt("currentBookId", 1)
        set(value) = prefs.edit() { putInt("currentBookId", value) }

    var browseFilter: QuestionFilter
        get() = QuestionFilter.fromInt(prefs.getInt("browseFilter", QuestionFilter.ALL.value))
        set(value) = prefs.edit { putInt("browseFilter", value.value) }

    // 试题数量选择
    var numOfChoice: Int
        get() = prefs.getInt("numOfChoice", 5)
        set(value) = prefs.edit() { putInt("numOfChoice", value) }

    var numOfJudge: Int
        get() = prefs.getInt("judgeOfChoice", 5)
        set(value) = prefs.edit() { putInt("judgeOfChoice", value) }

}
